/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package l2s.gameserver.scripts.quests;

import l2s.gameserver.model.L2World;
import l2s.gameserver.model.actor.L2Npc;
import l2s.gameserver.model.actor.instance.L2PcInstance;
import l2s.gameserver.model.quest.Quest;
import l2s.gameserver.model.quest.QuestState;
import l2s.gameserver.model.quest.QuestTimer;
import l2s.gameserver.scripting.ScriptFile;

public class Q220_TestimonyOfGlory extends Quest implements ScriptFile
{
	private static final String qn = "Q220_TestimonyOfGlory";
	private static final int Vokian = 30514;
	private static final int Chianta = 30642;
	private static final int Manakia = 30515;
	private static final int Kasman = 30501;
	private static final int Voltar = 30615;
	private static final int Kepra = 30616;
	private static final int Burai = 30617;
	private static final int Harak = 30618;
	private static final int Driko = 30619;
	private static final int Tanapi = 30571;
	private static final int Kakai = 30565;
	private static final int VokiansOrder = 3204;
	private static final int ManashenShard = 3205;
	private static final int TyrantTalon = 3206;
	private static final int GuardianBasiliskFang = 3207;
	private static final int VokiansOrder2 = 3208;
	private static final int NecklaceOfAuthority = 3209;
	private static final int ChiantaOrder1st = 3210;
	private static final int ScepterOfBreka = 3211;
	private static final int ScepterOfEnku = 3212;
	private static final int ScepterOfVuku = 3213;
	private static final int ScepterOfTurek = 3214;
	private static final int ScepterOfTunath = 3215;
	private static final int ChiantasOrder2rd = 3216;
	private static final int ChiantasOrder3rd = 3217;
	private static final int TamlinOrcSkull = 3218;
	private static final int TimakOrcHead = 3219;
	private static final int ScepterBox = 3220;
	private static final int PashikasHead = 3221;
	private static final int VultusHead = 3222;
	private static final int GloveOfVoltar = 3223;
	private static final int EnkuOverlordHead = 3224;
	private static final int GloveOfKepra = 3225;
	private static final int MakumBugbearHead = 3226;
	private static final int GloveOfBurai = 3227;
	private static final int ManakiaLetter1st = 3228;
	private static final int ManakiaLetter2st = 3229;
	private static final int KasmansLetter1rd = 3230;
	private static final int KasmansLetter2rd = 3231;
	private static final int KasmansLetter3rd = 3232;
	private static final int DrikosContract = 3233;
	private static final int StakatoDroneHusk = 3234;
	private static final int TanapisOrder = 3235;
	private static final int ScepterOfTantos = 3236;
	private static final int RitualBox = 3237;
	private static final int MarkOfGlory = 3203;
	private static final int Tyrant = 20192;
	private static final int TyrantKingpin = 20193;
	private static final int GuardianBasilisk = 20550;
	private static final int ManashenGargoyle = 20563;
	private static final int MarshStakatoDrone = 20234;
	private static final int PashikasSonOfVoltarQuestMonster = 27080;
	private static final int VultusSonOfVoltarQuestMonster = 27081;
	private static final int EnkuOrcOverlordQuestMonster = 27082;
	private static final int MakumBugbearThugQuestMonster = 27083;
	private static final int TimakOrc = 20583;
	private static final int TimakOrcArcher = 20584;
	private static final int TimakOrcSoldier = 20585;
	private static final int TimakOrcWarrior = 20586;
	private static final int TimakOrcShaman = 20587;
	private static final int TimakOrcOverlord = 20588;
	private static final int TamlinOrc = 20601;
	private static final int TamlinOrcArcher = 20602;
	private static final int RagnaOrcOverlord = 20778;
	private static final int RagnaOrcSeer = 20779;
	private static final int RevenantOfTantosChief = 27086;
	private static final int[][] DROPLIST_COND =
	{
		{
			1,
			0,
			ManashenGargoyle,
			VokiansOrder,
			ManashenShard,
			10,
			70,
			1
		},
		{
			1,
			0,
			Tyrant,
			VokiansOrder,
			TyrantTalon,
			10,
			70,
			1
		},
		{
			1,
			0,
			TyrantKingpin,
			VokiansOrder,
			TyrantTalon,
			10,
			70,
			1
		},
		{
			1,
			0,
			GuardianBasilisk,
			VokiansOrder,
			GuardianBasiliskFang,
			10,
			70,
			1
		},
		{
			4,
			0,
			MarshStakatoDrone,
			DrikosContract,
			StakatoDroneHusk,
			30,
			70,
			1
		},
		{
			4,
			0,
			EnkuOrcOverlordQuestMonster,
			GloveOfKepra,
			EnkuOverlordHead,
			4,
			100,
			1
		},
		{
			4,
			0,
			MakumBugbearThugQuestMonster,
			GloveOfBurai,
			MakumBugbearHead,
			2,
			100,
			1
		},
		{
			6,
			0,
			TimakOrc,
			ChiantasOrder3rd,
			TimakOrcHead,
			20,
			50,
			1
		},
		{
			6,
			0,
			TimakOrcArcher,
			ChiantasOrder3rd,
			TimakOrcHead,
			20,
			60,
			1
		},
		{
			6,
			0,
			TimakOrcSoldier,
			ChiantasOrder3rd,
			TimakOrcHead,
			20,
			70,
			1
		},
		{
			6,
			0,
			TimakOrcWarrior,
			ChiantasOrder3rd,
			TimakOrcHead,
			20,
			80,
			1
		},
		{
			6,
			0,
			TimakOrcShaman,
			ChiantasOrder3rd,
			TimakOrcHead,
			20,
			90,
			1
		},
		{
			6,
			0,
			TimakOrcOverlord,
			ChiantasOrder3rd,
			TimakOrcHead,
			20,
			100,
			1
		},
		{
			6,
			0,
			TamlinOrc,
			ChiantasOrder3rd,
			TamlinOrcSkull,
			20,
			50,
			1
		},
		{
			6,
			0,
			TamlinOrcArcher,
			ChiantasOrder3rd,
			TamlinOrcSkull,
			20,
			60,
			1
		}
	};
	private static boolean QuestProf = true;
	
	public Q220_TestimonyOfGlory(int questId, String name, String descr)
	{
		super(questId, name, descr);
		addStartNpc(Vokian);
		addTalkId(Chianta);
		addTalkId(Manakia);
		addTalkId(Kasman);
		addTalkId(Voltar);
		addTalkId(Kepra);
		addTalkId(Burai);
		addTalkId(Harak);
		addTalkId(Driko);
		addTalkId(Tanapi);
		addTalkId(Kakai);
		for (int[] element : DROPLIST_COND)
		{
			addKillId(element[2]);
		}
		addKillId(PashikasSonOfVoltarQuestMonster);
		addKillId(VultusSonOfVoltarQuestMonster);
		addKillId(RagnaOrcOverlord);
		addKillId(RagnaOrcSeer);
		addKillId(RevenantOfTantosChief);
		questItemIds = new int[]
		{
			VokiansOrder,
			VokiansOrder2,
			NecklaceOfAuthority,
			ChiantaOrder1st,
			ManakiaLetter1st,
			ManakiaLetter2st,
			KasmansLetter1rd,
			KasmansLetter2rd,
			KasmansLetter3rd,
			ScepterOfBreka,
			PashikasHead,
			VultusHead,
			GloveOfVoltar,
			GloveOfKepra,
			ScepterOfEnku,
			ScepterOfTurek,
			GloveOfBurai,
			ScepterOfTunath,
			DrikosContract,
			ChiantasOrder2rd,
			ChiantasOrder3rd,
			ScepterBox,
			TanapisOrder,
			ScepterOfTantos,
			RitualBox,
			ManashenShard,
			TyrantTalon,
			GuardianBasiliskFang,
			StakatoDroneHusk,
			EnkuOverlordHead,
			MakumBugbearHead,
			TimakOrcHead,
			TamlinOrcSkull
		};
	}
	
	@Override
	public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
	{
		String htmltext = event;
		QuestState st = player.getQuestState(qn);
		if (event.equalsIgnoreCase("RETURN"))
		{
			return null;
		}
		else if (event.equalsIgnoreCase("30514-05.htm"))
		{
			st.set("cond", "1");
			st.setState(Quest.STATE_STARTED);
			st.playSound(QuestState.SOUND_ACCEPT);
			st.giveItems(VokiansOrder, 1);
			st.giveItems(7562, 64);
		}
		else if (event.equalsIgnoreCase("30642-03.htm"))
		{
			st.takeItems(VokiansOrder2, -1);
			st.giveItems(ChiantaOrder1st, 1);
			st.set("cond", "4");
			st.setState(Quest.STATE_STARTED);
		}
		else if (event.equalsIgnoreCase("30571-03.htm"))
		{
			st.takeItems(ScepterBox, -1);
			st.giveItems(TanapisOrder, 1);
			st.set("cond", "9");
			st.setState(Quest.STATE_STARTED);
		}
		else if (event.equalsIgnoreCase("30642-07.htm"))
		{
			st.takeItems(ScepterOfBreka, -1);
			st.takeItems(ScepterOfEnku, -1);
			st.takeItems(ScepterOfVuku, -1);
			st.takeItems(ScepterOfTurek, -1);
			st.takeItems(ScepterOfTunath, -1);
			st.takeItems(ChiantaOrder1st, -1);
			if (st.getPlayer().getLevel() >= 38)
			{
				st.giveItems(ChiantasOrder3rd, 1);
				st.set("cond", "6");
				st.setState(Quest.STATE_STARTED);
			}
			else
			{
				htmltext = "30642-06.htm";
				st.giveItems(ChiantasOrder2rd, 1);
			}
		}
		else if (event.equalsIgnoreCase("BREKA"))
		{
			if (st.getQuestItemsCount(ScepterOfBreka) > 0)
			{
				htmltext = "30515-02.htm";
			}
			else
			{
				if (st.getQuestItemsCount(ManakiaLetter1st) > 0)
				{
					htmltext = "30515-04.htm";
				}
				else
				{
					htmltext = "30515-03.htm";
					st.giveItems(ManakiaLetter1st, 1);
				}
			}
		}
		else if (event.equalsIgnoreCase("ENKU"))
		{
			if (st.getQuestItemsCount(ScepterOfEnku) > 0)
			{
				htmltext = "30515-05.htm";
			}
			else
			{
				if (st.getQuestItemsCount(ManakiaLetter2st) > 0)
				{
					htmltext = "30515-07.htm";
				}
				else
				{
					htmltext = "30515-06.htm";
					st.giveItems(ManakiaLetter2st, 1);
				}
			}
		}
		else if (event.equalsIgnoreCase("VUKU"))
		{
			if (st.getQuestItemsCount(ScepterOfVuku) > 0)
			{
				htmltext = "30501-02.htm";
			}
			else
			{
				if (st.getQuestItemsCount(KasmansLetter1rd) > 0)
				{
					htmltext = "30501-04.htm";
				}
				else
				{
					htmltext = "30501-03.htm";
					st.giveItems(KasmansLetter1rd, 1);
				}
			}
		}
		else if (event.equalsIgnoreCase("TUREK"))
		{
			if (st.getQuestItemsCount(ScepterOfTurek) > 0)
			{
				htmltext = "30501-05.htm";
			}
			else
			{
				if (st.getQuestItemsCount(KasmansLetter2rd) > 0)
				{
					htmltext = "30501-07.htm";
				}
				else
				{
					htmltext = "30501-06.htm";
					st.giveItems(KasmansLetter2rd, 1);
				}
			}
		}
		else if (event.equalsIgnoreCase("TUNATH"))
		{
			if (st.getQuestItemsCount(ScepterOfTunath) > 0)
			{
				htmltext = "30501-08.htm";
			}
			else
			{
				if (st.getQuestItemsCount(KasmansLetter3rd) > 0)
				{
					htmltext = "30501-10.htm";
				}
				else
				{
					htmltext = "30501-09.htm";
					st.giveItems(KasmansLetter3rd, 1);
				}
			}
		}
		else if (event.equalsIgnoreCase("30615-04.htm"))
		{
			int spawn = 0;
			L2Npc isQuest = L2World.getInstance().getNpcById(PashikasSonOfVoltarQuestMonster);
			if (isQuest != null)
			{
				spawn = 1;
			}
			isQuest = L2World.getInstance().getNpcById(PashikasSonOfVoltarQuestMonster);
			if (isQuest != null)
			{
				spawn = 1;
			}
			if (spawn == 1) // если хоть один моб есть в мире, ставим таймер на
			{
				QuestTimer timer = getQuestTimer("Wait1", npc, player);
				if (timer == null)
				{
					startQuestTimer("Wait1", 300000, npc, player, false);
				}
				htmltext = "<html><head><body>Plees wait 5 minutes</body></html>";
			}
			else
			{
				st.takeItems(ManakiaLetter1st, -1);
				st.giveItems(GloveOfVoltar, 1);
				QuestTimer timer = getQuestTimer("Wait1", npc, player);
				if (timer != null)
				{
					timer.cancel();
				}
				startQuestTimer("PashikasSonOfVoltarQuestMonster", 200000, npc, player, false);
				startQuestTimer("VultusSonOfVoltarQuestMonster", 200000, npc, player, false);
				addSpawn(PashikasSonOfVoltarQuestMonster, player, true, 0, true);
				addSpawn(VultusSonOfVoltarQuestMonster, player, true, 0, true);
				st.playSound(QuestState.SOUND_BEFORE_BATTLE);
			}
		}
		else if (event.equalsIgnoreCase("30616-04.htm"))
		{
			L2Npc isQuest = L2World.getInstance().getNpcById(EnkuOrcOverlordQuestMonster);
			if (isQuest != null)
			{
				QuestTimer timer = getQuestTimer("Wait2", npc, player);
				if (timer == null)
				{
					startQuestTimer("Wait2", 300000, npc, player, false);
				}
				htmltext = "<html><head><body>Plees wait 5 minutes</body></html>";
			}
			else
			{
				st.takeItems(ManakiaLetter2st, -1);
				st.giveItems(GloveOfKepra, 1);
				QuestTimer timer = getQuestTimer("Wait2", npc, player);
				if (timer != null)
				{
					timer.cancel();
				}
				startQuestTimer("EnkuOrcOverlordQuestMonster", 200000, npc, player, false);
				addSpawn(EnkuOrcOverlordQuestMonster, player, true, 0, true);
				addSpawn(EnkuOrcOverlordQuestMonster, player, true, 0, true);
				addSpawn(EnkuOrcOverlordQuestMonster, player, true, 0, true);
				addSpawn(EnkuOrcOverlordQuestMonster, player, true, 0, true);
				st.playSound(QuestState.SOUND_BEFORE_BATTLE);
			}
		}
		else if (event.equalsIgnoreCase("30617-04.htm"))
		{
			L2Npc isQuest = L2World.getInstance().getNpcById(MakumBugbearThugQuestMonster);
			if (isQuest != null)
			{
				QuestTimer timer = getQuestTimer("Wait3", npc, player);
				if (timer == null)
				{
					startQuestTimer("Wait3", 300000, npc, player, false);
				}
				htmltext = "<html><head><body>Plees wait 5 minutes</body></html>";
			}
			else
			{
				st.takeItems(KasmansLetter2rd, -1);
				st.giveItems(GloveOfBurai, 1);
				QuestTimer timer = getQuestTimer("Wait3", npc, player);
				if (timer != null)
				{
					timer.cancel();
				}
				startQuestTimer("MakumBugbearThugQuestMonster", 200000, npc, player, false);
				addSpawn(MakumBugbearThugQuestMonster, player, true, 0, true);
				addSpawn(MakumBugbearThugQuestMonster, player, true, 0, true);
				st.playSound(QuestState.SOUND_BEFORE_BATTLE);
			}
		}
		else if (event.equalsIgnoreCase("30618-03.htm"))
		{
			st.takeItems(KasmansLetter3rd, -1);
			st.giveItems(ScepterOfTunath, 1);
			if ((st.getQuestItemsCount(ScepterOfBreka) != 0) && (st.getQuestItemsCount(ScepterOfEnku) != 0) && (st.getQuestItemsCount(ScepterOfVuku) != 0) && (st.getQuestItemsCount(ScepterOfTurek) != 0) && (st.getQuestItemsCount(ScepterOfTunath) != 0))
			{
				st.set("cond", "5");
				st.setState(Quest.STATE_STARTED);
			}
		}
		else if (event.equalsIgnoreCase("30619-03.htm"))
		{
			st.takeItems(KasmansLetter1rd, -1);
			st.giveItems(DrikosContract, 1);
		}
		else if (event.equalsIgnoreCase("Wait1") || event.equalsIgnoreCase("PashikasSonOfVoltarQuestMonster") || event.equalsIgnoreCase("VultusSonOfVoltarQuestMonster"))
		{
			L2Npc isQuest = L2World.getInstance().getNpcById(PashikasSonOfVoltarQuestMonster);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			isQuest = L2World.getInstance().getNpcById(VultusSonOfVoltarQuestMonster);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			QuestTimer timer = getQuestTimer("Wait1", npc, player);
			if (timer != null)
			{
				timer.cancel();
			}
			timer = getQuestTimer("PashikasSonOfVoltarQuestMonster", npc, player);
			if (timer != null)
			{
				timer.cancel();
			}
		}
		else if (event.equalsIgnoreCase("Wait2") || event.equalsIgnoreCase("EnkuOrcOverlordQuestMonster"))
		{
			L2Npc isQuest = L2World.getInstance().getNpcById(EnkuOrcOverlordQuestMonster);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			isQuest = L2World.getInstance().getNpcById(EnkuOrcOverlordQuestMonster);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			isQuest = L2World.getInstance().getNpcById(EnkuOrcOverlordQuestMonster);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			isQuest = L2World.getInstance().getNpcById(EnkuOrcOverlordQuestMonster);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			QuestTimer timer = getQuestTimer("Wait2", npc, player);
			if (timer != null)
			{
				timer.cancel();
			}
			timer = getQuestTimer("EnkuOrcOverlordQuestMonster", npc, player);
			if (timer != null)
			{
				timer.cancel();
			}
		}
		else if (event.equalsIgnoreCase("Wait3") || event.equalsIgnoreCase("MakumBugbearThugQuestMonster"))
		{
			L2Npc isQuest = L2World.getInstance().getNpcById(MakumBugbearThugQuestMonster);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			isQuest = L2World.getInstance().getNpcById(MakumBugbearThugQuestMonster);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			QuestTimer timer = getQuestTimer("Wait3", npc, player);
			if (timer != null)
			{
				timer.cancel();
			}
			timer = getQuestTimer("MakumBugbearThugQuestMonster", npc, player);
			if (timer != null)
			{
				timer.cancel();
			}
		}
		else if (event.equalsIgnoreCase("Wait4") || event.equalsIgnoreCase("RevenantOfTantosChief"))
		{
			L2Npc isQuest = L2World.getInstance().getNpcById(RevenantOfTantosChief);
			if (isQuest != null)
			{
				isQuest.deleteMe();
			}
			QuestTimer timer = getQuestTimer("Wait4", npc, player);
			if (timer != null)
			{
				timer.cancel();
			}
			timer = getQuestTimer("RevenantOfTantosChief", npc, player);
			if (timer != null)
			{
				timer.cancel();
			}
		}
		return htmltext;
	}
	
	@Override
	public String onTalk(L2Npc npc, L2PcInstance player)
	{
		int npcId = npc.getNpcId();
		QuestState st = player.getQuestState(qn);
		String htmltext = getNoQuestMsg();
		int cond = st.getInt("cond");
		if (npcId == Vokian)
		{
			if (st.getQuestItemsCount(MarkOfGlory) != 0)
			{
				htmltext = getAlreadyCompletedMsg();
				st.exitQuest(true);
			}
			else if (cond == 0)
			{
				if ((st.getPlayer().getClassId().getId() == 45) || (st.getPlayer().getClassId().getId() == 47) || (st.getPlayer().getClassId().getId() == 50))
				{
					if (st.getPlayer().getLevel() >= 37)
					{
						htmltext = "30514-03.htm";
					}
					else
					{
						htmltext = "30514-01.htm";
						st.exitQuest(true);
					}
				}
				else
				{
					htmltext = "30514-02.htm";
					st.exitQuest(true);
				}
			}
			else if (cond == 1)
			{
				htmltext = "30514-06.htm";
			}
			else if (cond == 2)
			{
				st.takeItems(VokiansOrder, -1);
				st.takeItems(ManashenShard, -10);
				st.takeItems(TyrantTalon, -10);
				st.takeItems(GuardianBasiliskFang, -10);
				st.giveItems(VokiansOrder2, 1);
				st.giveItems(NecklaceOfAuthority, 1);
				htmltext = "30514-08.htm";
				st.set("cond", "3");
				st.setState(Quest.STATE_STARTED);
			}
			else if (cond == 3)
			{
				htmltext = "30514-09.htm";
			}
			else if (cond == 4)
			{
				htmltext = "30514-10.htm";
			}
		}
		else if (npcId == Chianta)
		{
			if (cond == 3)
			{
				htmltext = "30642-01.htm";
			}
			else if (cond == 4)
			{
				htmltext = "30642-04.htm";
			}
			else if (cond == 5)
			{
				if (st.getQuestItemsCount(ChiantaOrder1st) > 0)
				{
					htmltext = "30642-05.htm";
				}
				else if (st.getQuestItemsCount(ChiantasOrder2rd) > 0)
				{
					if (st.getPlayer().getLevel() >= 38)
					{
						st.takeItems(ChiantasOrder2rd, -1);
						st.giveItems(ChiantasOrder3rd, 1);
						htmltext = "30642-09.htm";
						st.set("cond", "6");
						st.setState(Quest.STATE_STARTED);
					}
					else
					{
						htmltext = "30642-08.htm";
					}
				}
			}
			else if (cond == 6)
			{
				htmltext = "30642-10.htm";
			}
			else if (cond == 7)
			{
				st.takeItems(NecklaceOfAuthority, -1);
				st.takeItems(ChiantasOrder3rd, -1);
				st.takeItems(TamlinOrcSkull, -1);
				st.takeItems(TimakOrcHead, -1);
				st.giveItems(ScepterBox, 1);
				htmltext = "30642-11.htm";
				st.set("cond", "8");
				st.setState(Quest.STATE_STARTED);
			}
			else if (cond == 8)
			{
				htmltext = "30642-12.htm";
			}
		}
		else if (npcId == Manakia)
		{
			if (cond == 4)
			{
				htmltext = "30515-01.htm";
			}
		}
		else if (npcId == Kasman)
		{
			if (cond == 4)
			{
				htmltext = "30501-01.htm";
			}
		}
		else if (npcId == Voltar)
		{
			if (cond == 4)
			{
				if (st.getQuestItemsCount(ManakiaLetter1st) > 0)
				{
					htmltext = "30615-02.htm";
				}
				else if ((st.getQuestItemsCount(GloveOfVoltar) > 0) && ((st.getQuestItemsCount(PashikasHead) == 0) || (st.getQuestItemsCount(VultusHead) == 0)))
				{
					htmltext = "30615-05.htm";
					int sound = 0;
					L2Npc isQuest = L2World.getInstance().getNpcById(PashikasSonOfVoltarQuestMonster);
					if (isQuest == null)
					{
						sound = 1;
						addSpawn(PashikasSonOfVoltarQuestMonster, player, true, 0, true);
						startQuestTimer("PashikasSonOfVoltarQuestMonster", 200000, npc, player, false);
					}
					isQuest = L2World.getInstance().getNpcById(VultusSonOfVoltarQuestMonster);
					if (isQuest == null)
					{
						sound = 1;
						addSpawn(VultusSonOfVoltarQuestMonster, player, true, 0, true);
						startQuestTimer("VultusSonOfVoltarQuestMonster", 200000, npc, player, false);
					}
					if (sound == 1)
					{
						st.playSound(QuestState.SOUND_BEFORE_BATTLE);
						QuestTimer timer = getQuestTimer("Wait1", npc, player);
						if (timer != null)
						{
							timer.cancel();
						}
					}
					else
					{
						startQuestTimer("Wait1", 300000, npc, player, false);
						htmltext = "<html><head><body>Plees wait 5 minutes</body></html>";
					}
				}
				else if ((st.getQuestItemsCount(PashikasHead) > 0) && (st.getQuestItemsCount(VultusHead) > 0))
				{
					st.takeItems(PashikasHead, -1);
					st.takeItems(VultusHead, -1);
					st.takeItems(GloveOfVoltar, -1);
					st.giveItems(ScepterOfBreka, 1);
					htmltext = "30615-06.htm";
					if ((st.getQuestItemsCount(ScepterOfBreka) > 0) && (st.getQuestItemsCount(ScepterOfEnku) > 0) && (st.getQuestItemsCount(ScepterOfVuku) > 0) && (st.getQuestItemsCount(ScepterOfTurek) > 0) && (st.getQuestItemsCount(ScepterOfTunath) > 0))
					{
						st.set("cond", "5");
						st.setState(Quest.STATE_STARTED);
						st.playSound(QuestState.SOUND_MIDDLE);
					}
					else
					{
						st.playSound(QuestState.SOUND_ITEMGET);
					}
				}
				else if (st.getQuestItemsCount(ScepterOfBreka) > 0)
				{
					htmltext = "30615-07.htm";
				}
				else
				{
					htmltext = "30615-01.htm";
				}
			}
		}
		else if (npcId == Kepra)
		{
			if (cond == 4)
			{
				if (st.getQuestItemsCount(ManakiaLetter2st) > 0)
				{
					htmltext = "30616-02.htm";
				}
				else if ((st.getQuestItemsCount(GloveOfKepra) > 0) && (st.getQuestItemsCount(EnkuOverlordHead) < 4))
				{
					htmltext = "30616-05.htm";
					L2Npc isQuest = L2World.getInstance().getNpcById(EnkuOrcOverlordQuestMonster);
					if (isQuest != null)
					{
						startQuestTimer("Wait2", 300000, npc, player, false);
						htmltext = "<html><head><body>Plees wait 5 minutes</body></html>";
					}
					else
					{
						QuestTimer timer = getQuestTimer("Wait2", npc, player);
						if (timer != null)
						{
							timer.cancel();
						}
						startQuestTimer("EnkuOrcOverlordQuestMonster", 200000, npc, player, false);
						addSpawn(EnkuOrcOverlordQuestMonster, player, true, 0, true);
						addSpawn(EnkuOrcOverlordQuestMonster, player, true, 0, true);
						addSpawn(EnkuOrcOverlordQuestMonster, player, true, 0, true);
						addSpawn(EnkuOrcOverlordQuestMonster, player, true, 0, true);
						st.playSound(QuestState.SOUND_BEFORE_BATTLE);
					}
				}
				else if (st.getQuestItemsCount(EnkuOverlordHead) >= 4)
				{
					htmltext = "30616-06.htm";
					st.takeItems(EnkuOverlordHead, -1);
					st.takeItems(GloveOfKepra, -1);
					st.giveItems(ScepterOfEnku, 1);
					if ((st.getQuestItemsCount(ScepterOfBreka) > 0) && (st.getQuestItemsCount(ScepterOfEnku) > 0) && (st.getQuestItemsCount(ScepterOfVuku) > 0) && (st.getQuestItemsCount(ScepterOfTurek) > 0) && (st.getQuestItemsCount(ScepterOfTunath) > 0))
					{
						st.set("cond", "5");
						st.setState(Quest.STATE_STARTED);
						st.playSound(QuestState.SOUND_MIDDLE);
					}
					else
					{
						st.playSound(QuestState.SOUND_ITEMGET);
					}
				}
				else if (st.getQuestItemsCount(ScepterOfEnku) > 0)
				{
					htmltext = "30616-07.htm";
				}
				else
				{
					htmltext = "30616-01.htm";
				}
			}
		}
		else if (npcId == Burai)
		{
			if (cond == 4)
			{
				if (st.getQuestItemsCount(KasmansLetter2rd) > 0)
				{
					htmltext = "30617-02.htm";
				}
				else if ((st.getQuestItemsCount(GloveOfBurai) > 0) && (st.getQuestItemsCount(MakumBugbearHead) < 2))
				{
					htmltext = "30617-05.htm";
					L2Npc isQuest = L2World.getInstance().getNpcById(MakumBugbearThugQuestMonster);
					if (isQuest != null)
					{
						startQuestTimer("Wait3", 300000, npc, player, false);
						htmltext = "<html><head><body>Plees wait 5 minutes</body></html>";
					}
					else
					{
						QuestTimer timer = getQuestTimer("Wait3", npc, player);
						if (timer != null)
						{
							timer.cancel();
						}
						startQuestTimer("MakumBugbearThugQuestMonster", 200000, npc, player, false);
						addSpawn(MakumBugbearThugQuestMonster, player, true, 0, true);
						addSpawn(MakumBugbearThugQuestMonster, player, true, 0, true);
						st.playSound(QuestState.SOUND_BEFORE_BATTLE);
					}
				}
				else if (st.getQuestItemsCount(MakumBugbearHead) == 2)
				{
					htmltext = "30617-06.htm";
					st.takeItems(MakumBugbearHead, -1);
					st.takeItems(GloveOfBurai, -1);
					st.giveItems(ScepterOfTurek, 1);
					if ((st.getQuestItemsCount(ScepterOfBreka) > 0) && (st.getQuestItemsCount(ScepterOfEnku) > 0) && (st.getQuestItemsCount(ScepterOfVuku) > 0) && (st.getQuestItemsCount(ScepterOfTurek) > 0) && (st.getQuestItemsCount(ScepterOfTunath) > 0))
					{
						st.set("cond", "5");
						st.setState(Quest.STATE_STARTED);
						st.playSound(QuestState.SOUND_MIDDLE);
					}
					else
					{
						st.playSound(QuestState.SOUND_ITEMGET);
					}
				}
				else if (st.getQuestItemsCount(ScepterOfTurek) > 0)
				{
					htmltext = "30617-07.htm";
				}
				else
				{
					htmltext = "30617-01.htm";
				}
			}
		}
		else if (npcId == Harak)
		{
			if (cond == 4)
			{
				if (st.getQuestItemsCount(KasmansLetter3rd) > 0)
				{
					htmltext = "30618-02.htm";
				}
				else if (st.getQuestItemsCount(ScepterOfTunath) > 0)
				{
					htmltext = "30618-04.htm";
				}
				else
				{
					htmltext = "30618-01.htm";
				}
			}
		}
		else if (npcId == Driko)
		{
			if (cond == 4)
			{
				if (st.getQuestItemsCount(KasmansLetter1rd) > 0)
				{
					htmltext = "30619-02.htm";
				}
				else if (st.getQuestItemsCount(DrikosContract) > 0)
				{
					if (st.getQuestItemsCount(StakatoDroneHusk) >= 30)
					{
						htmltext = "30619-05.htm";
						st.takeItems(StakatoDroneHusk, -1);
						st.takeItems(DrikosContract, -1);
						st.giveItems(ScepterOfVuku, 1);
						if ((st.getQuestItemsCount(ScepterOfBreka) > 0) && (st.getQuestItemsCount(ScepterOfEnku) > 0) && (st.getQuestItemsCount(ScepterOfVuku) > 0) && (st.getQuestItemsCount(ScepterOfTurek) > 0) && (st.getQuestItemsCount(ScepterOfTunath) > 0))
						{
							st.set("cond", "5");
							st.setState(Quest.STATE_STARTED);
							st.playSound(QuestState.SOUND_MIDDLE);
						}
						else
						{
							st.playSound(QuestState.SOUND_ITEMGET);
						}
					}
					else
					{
						htmltext = "30619-04.htm";
					}
				}
				else if (st.getQuestItemsCount(ScepterOfVuku) > 0)
				{
					htmltext = "30619-06.htm";
				}
				else
				{
					htmltext = "30619-01.htm";
				}
			}
		}
		else if (npcId == Tanapi)
		{
			if (cond == 8)
			{
				htmltext = "30571-01.htm";
			}
			else if (cond == 9)
			{
				htmltext = "30571-04.htm";
			}
			else if (cond == 10)
			{
				st.takeItems(ScepterOfTantos, -1);
				st.takeItems(TanapisOrder, -1);
				st.giveItems(RitualBox, 1);
				htmltext = "30571-05.htm";
				st.set("cond", "11");
				st.setState(Quest.STATE_STARTED);
			}
			else if (cond == 11)
			{
				htmltext = "30571-06.htm";
			}
		}
		if ((npcId == Kakai) && (cond == 11))
		{
			st.takeItems(RitualBox, -1);
			st.giveItems(MarkOfGlory, 1);
			st.getPlayer().addExpAndSp(91457, 2500);
			htmltext = "30565-02.htm";
			st.playSound(QuestState.SOUND_FINISH);
			st.exitQuest(true);
		}
		return htmltext;
	}
	
	@Override
	public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
	{
		int npcId = npc.getNpcId();
		QuestState st = checkPlayerState(player, npc, STATE_STARTED);
		if (st == null)
		{
			return null;
		}
		int cond = st.getInt("cond");
		for (int[] element : DROPLIST_COND)
		{
			if ((cond == element[0]) && (npcId == element[2]))
			{
				if ((element[3] == 0) || (st.getQuestItemsCount(element[3]) > 0))
				{
					if (element[5] == 0)
					{
						st.rollAndGive(element[4], element[7], element[6], QuestProf);
					}
					else if (st.rollAndGive(element[4], element[7], element[7], element[5], element[6], QuestProf))
					{
						if ((element[1] != cond) && (element[1] != 0))
						{
							st.set("cond", String.valueOf(element[1]));
							st.setState(Quest.STATE_STARTED);
						}
					}
				}
			}
		}
		if ((cond == 1) && (st.getQuestItemsCount(TyrantTalon) >= 10) && (st.getQuestItemsCount(GuardianBasiliskFang) >= 10) && (st.getQuestItemsCount(ManashenShard) >= 10))
		{
			st.set("cond", "2");
			st.setState(Quest.STATE_STARTED);
		}
		else if (cond == 4)
		{
			if (npcId == PashikasSonOfVoltarQuestMonster)
			{
				QuestTimer timer = getQuestTimer("PashikasSonOfVoltarQuestMonster", npc, player);
				if (timer != null)
				{
					timer.cancel();
				}
				L2Npc isQuest = L2World.getInstance().getNpcById(PashikasSonOfVoltarQuestMonster);
				if (isQuest != null)
				{
					isQuest.deleteMe();
				}
				if ((st.getQuestItemsCount(GloveOfVoltar) > 0) && (st.getQuestItemsCount(PashikasHead) == 0))
				{
					st.giveItems(PashikasHead, 1);
				}
			}
			else if (npcId == VultusSonOfVoltarQuestMonster)
			{
				QuestTimer timer = getQuestTimer("VultusSonOfVoltarQuestMonster", npc, player);
				if (timer != null)
				{
					timer.cancel();
				}
				L2Npc isQuest = L2World.getInstance().getNpcById(VultusSonOfVoltarQuestMonster);
				if (isQuest != null)
				{
					isQuest.deleteMe();
				}
				if ((st.getQuestItemsCount(GloveOfVoltar) > 0) && (st.getQuestItemsCount(VultusHead) == 0))
				{
					st.giveItems(VultusHead, 1);
				}
			}
		}
		else if ((cond == 6) && (st.getQuestItemsCount(TimakOrcHead) >= 20) && (st.getQuestItemsCount(TamlinOrcSkull) >= 20))
		{
			st.set("cond", "7");
			st.setState(Quest.STATE_STARTED);
		}
		else if (cond == 9)
		{
			if ((npcId == RagnaOrcOverlord) || (npcId == RagnaOrcSeer))
			{
				L2Npc isQuest = L2World.getInstance().getNpcById(RevenantOfTantosChief);
				if (isQuest == null)
				{
					startQuestTimer("RevenantOfTantosChief", 300000, npc, player, false);
					addSpawn(RevenantOfTantosChief, player, true, 0, true);
					st.playSound(QuestState.SOUND_BEFORE_BATTLE);
				}
				else
				{
					QuestTimer timer = getQuestTimer("Wait4", npc, player);
					if (timer == null)
					{
						startQuestTimer("Wait4", 300000, npc, player, false);
					}
				}
			}
			else if (npcId == RevenantOfTantosChief)
			{
				QuestTimer timer = getQuestTimer("RevenantOfTantosChief", npc, player);
				if (timer != null)
				{
					timer.cancel();
				}
				timer = getQuestTimer("Wait4", npc, player);
				if (timer != null)
				{
					timer.cancel();
				}
				L2Npc isQuest = L2World.getInstance().getNpcById(RevenantOfTantosChief);
				if (isQuest != null)
				{
					isQuest.deleteMe();
				}
				st.giveItems(ScepterOfTantos, 1);
				st.set("cond", "10");
				st.setState(Quest.STATE_STARTED);
				st.playSound(QuestState.SOUND_MIDDLE);
			}
		}
		return null;
	}
	
	public static void onLoad()
	{
		new Q220_TestimonyOfGlory(220, qn, "Testimony Of Glory");
	}
}
